001    /**
002     * Created by IntelliJ IDEA.
003     * User: Wei Wang
004     * Date: Apr 25, 2003
005     * Time: 12:37:08 AM
006     */
007    
008    package EVolve.util.phasedetectors;
009    
010    import EVolve.visualization.XYViz.XYVisualization;
011    import EVolve.visualization.AxesPanel;
012    import EVolve.Scene;
013    import EVolve.util.HelperFuncs;
014    import javax.swing.*;
015    import java.awt.*;
016    
017    public class PhaseOperation {
018        private PhaseClipboard phaseClipboard;
019    
020        public PhaseOperation() {
021            phaseClipboard = new PhaseClipboard();
022        }
023    
024        public void add() {
025            XYVisualization workingViz = HelperFuncs.getActiveXYViz();
026    
027            if (workingViz == null) return;
028    
029            Scene.getUIManager().enablePhaseDetectorButton(false);
030    
031            workingViz.freeze(true);
032            AxesPanel canvas = (AxesPanel)((JScrollPane)workingViz.getPanel()).getViewport().getView();
033            canvas.setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR));
034            new PhaseAddRemover().beginAdd();
035        }
036    
037        public void remove() {
038            XYVisualization workingViz = HelperFuncs.getActiveXYViz();
039    
040            if (workingViz == null) return;
041    
042            Scene.getUIManager().enablePhaseDetectorButton(false);
043    
044            workingViz.freeze(true);
045            AxesPanel canvas = (AxesPanel)((JScrollPane)workingViz.getPanel()).getViewport().getView();
046            canvas.setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR));
047            new PhaseAddRemover().beginRemove();
048        }
049    
050        public void copyPhase() {
051            phaseClipboard.copyPhase();
052        }
053    
054        public void pastePhase() {
055            phaseClipboard.pastePhase();
056        }
057    
058        public boolean clipboardIsEmpty() {
059            return phaseClipboard.isEmpty();
060        }
061    
062        public void triggerPhases(int noiseTolerance) {
063            XYVisualization visual = HelperFuncs.getActiveXYViz();
064    
065            if ((visual == null)&&(visual.getPhaseDetector() == null)) {
066                Scene.showErrorMessage("No phase detector available.");
067                return;
068            }
069    
070            visual.getPhaseDetector().triggerPhases(noiseTolerance);
071        }
072    
073        public void undo() {
074            XYVisualization visual = HelperFuncs.getActiveXYViz();
075    
076            if ((visual == null)||(visual.getPhaseDetector() == null)) {
077                Scene.showErrorMessage("No undoable actions available.");
078                return;
079            }
080    
081            visual.getPhaseDetector().undo();
082        }
083    
084        public boolean undoable() {
085            XYVisualization visual = HelperFuncs.getActiveXYViz();
086    
087            if ((visual == null)||(visual.getPhaseDetector() == null)) {
088                return false;
089            }
090    
091            return visual.getPhaseDetector().undoable();
092        }
093    }